feat: xev Dynamic API + gitignore updates for Shadow support#704
feat: xev Dynamic API + gitignore updates for Shadow support#704
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Zig codebase to use libxev’s Dynamic API so the runtime can select the best available I/O backend (io_uring vs epoll), improving portability across Linux kernel versions and compatibility with Shadow. It also updates .gitignore to exclude additional local/tool-generated artifacts.
Changes:
- Switched
@import("xev")usages to@import("xev").Dynamicacross node, network, and CLI code. - Added a
detectBackend()helper and invoked it early in CLI startup and node test initialization. - Updated
.gitignoreto ignorezig-pkg/, Shadow outputs, and.idea/.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkgs/node/src/utils.zig | Introduces detectBackend() and moves node code to xev.Dynamic. |
| pkgs/node/src/testing.zig | Calls backend detection before initializing the event loop in tests. |
| pkgs/node/src/node.zig | Switches xev import for tests to xev.Dynamic. |
| pkgs/node/src/lib.zig | Re-exports detectBackend for external callers (CLI). |
| pkgs/node/src/clock.zig | Switches xev import to xev.Dynamic. |
| pkgs/network/src/mock.zig | Switches to xev.Dynamic and adds backend detection in tests. |
| pkgs/network/src/interface.zig | Switches xev import to xev.Dynamic. |
| pkgs/network/src/ethlibp2p.zig | Switches xev import to xev.Dynamic. |
| pkgs/cli/src/node.zig | Switches xev import to xev.Dynamic. |
| pkgs/cli/src/main.zig | Calls node_lib.detectBackend() early during CLI startup. |
| build.zig | Notes that xev backend override is no longer needed. |
| .gitignore | Ignores zig-pkg/, Shadow outputs, and JetBrains IDE files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pkgs/network/src/mock.zig
Outdated
| if (@hasDecl(xev, "detect")) xev.detect() catch @panic("no available xev backend"); | ||
| var loop = try xev.Loop.init(.{}); |
There was a problem hiding this comment.
This if (@hasDecl(xev, "detect")) xev.detect() ... backend-detection snippet is duplicated in multiple tests in this file. Consider factoring it into a small local helper (e.g., detectBackendOrPanic()), so the behavior/error handling stays consistent and future changes only need to be made once.
pkgs/network/src/mock.zig
Outdated
| if (@hasDecl(xev, "detect")) xev.detect() catch @panic("no available xev backend"); | ||
| var loop = try xev.Loop.init(.{}); | ||
| defer loop.deinit(); |
There was a problem hiding this comment.
This backend detection line duplicates the same xev.detect() snippet used earlier in this file. To reduce repetition (and keep the panic/error message consistent), consider extracting the detection into a single helper and calling it from each test before xev.Loop.init.
Switch from compile-time xev backend selection to the Dynamic API, which probes io_uring at runtime and falls back to epoll. This is needed for Shadow network simulator (no io_uring support) but also makes the binary portable across Linux kernel versions.
bb009e5 to
ddcfd5c
Compare
|
copilot suggestions seem appropriate, can you apply them/resolve them |
- Change detectBackend() to return error instead of panicking, so callers get the underlying error name for debugging - Update CLI main.zig to handle the error via ErrorHandler - Update testing.zig to propagate the error - Extract detectBackendOrFail() helper in mock.zig to eliminate duplicated xev.detect() snippets
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 11 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fixed |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pub fn init(allocator: Allocator, opts: NodeTestOptions) !NodeTestContext { | ||
| const utils = @import("./utils.zig"); | ||
| utils.detectBackend() catch |err| { | ||
| std.log.err("failed to detect I/O backend: {s}", .{@errorName(err)}); | ||
| return err; | ||
| }; |
There was a problem hiding this comment.
@import("./utils.zig") is being done inside NodeTestContext.init. In this codebase, file/module imports are typically declared at top-level with the other const ... = @import(...) statements; consider moving this to a top-level const utils = @import("./utils.zig"); to keep imports centralized and avoid function-local compile-time imports.
| /// Detect the best available I/O backend at runtime. | ||
| /// Factored out to avoid duplicating the detection snippet in every test. | ||
| fn detectBackendOrFail() !void { | ||
| if (@hasDecl(xev, "detect")) { | ||
| try xev.detect(); | ||
| } | ||
| } |
There was a problem hiding this comment.
detectBackendOrFail() duplicates the backend-detection logic introduced in pkgs/node/src/utils.zig (and now exported as @zeam/node.detectBackend). To avoid the two implementations drifting if libxev’s Dynamic API changes, consider centralizing this helper in a shared place (e.g. @zeam/utils) and calling it from both node and network tests.
| const xev = @import("xev").Dynamic; | ||
|
|
There was a problem hiding this comment.
This xev import appears unused in this file (no xev. references). If it’s not needed anymore, it should be removed to reduce confusion about where the event loop backend is configured.
| const xev = @import("xev").Dynamic; |
Summary
zig-pkg/cache, Shadow simulator outputs, and IDE filesDetails
xev Dynamic API
All
@import("xev")changed to@import("xev").Dynamic, which probes io_uring at runtime and falls back to epoll. AdetectBackend()helper inutils.zigis called early in main and in test setup.gitignore
zig-pkg/— local Zig package cache (should not be committed)shadow.yaml,shadow.data/— generated bylean-quickstart/run-shadow.sh.idea/— JetBrains IDE filesTest plan
lean-quickstart/run-shadow.sh